package com.marchsoft.dao;

import com.marchsoft.common.mapper.CommentMapper;
import com.marchsoft.domain.Activity;
import com.marchsoft.vo.UnDoMsg;
import org.apache.ibatis.annotations.*;
import com.marchsoft.vo.HistoryGroupExtra;
import com.marchsoft.vo.HistoryTeacherExtra;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Component;

import java.util.Date;

import java.util.List;

@Component
public interface ActivityMapper extends CommentMapper<Activity> {


    /**
     * 根据学生id查询历史导师的信息
     *
     * @param sid 学生id
     * @return 历史导师信息
     */
    @Select("SELECT a.tid a_tid,t.name t_name,a.a_time FROM activity a LEFT JOIN teacher t ON a.tid=t.tid WHERE a.sid=#{sid} AND (a.status=22 OR a.status=25)")
    @Results({
            @Result(column = "a_tid", property = "aTid"),
            @Result(column = "t_name", property = "teacherHistoryName"),
            @Result(column = "a_time", property = "interimTime"),
    })
    List<HistoryTeacherExtra> queryHistoryTeacherBySidWithStatus(Integer sid);

    /**
     * 根据学生id查询历史小组的信息
     *
     * @param sid 学生id
     * @return 历史小组信息
     */
    @Select("SELECT a.group_id,g.name g_name,a.a_time FROM activity a LEFT JOIN `group` g ON a.group_id=g.id WHERE a.sid=#{sid} AND (a.status=2 OR a.status=4)")
    @Results({
            @Result(column = "group_id", property = "aGid"),
            @Result(column = "g_name", property = "groupHistoryName"),
            @Result(column = "a_time", property = "interimTime"),
    })
    List<HistoryGroupExtra> queryHistoryGroupBySidWithStatus(Integer sid);

    /**
     * 根据老师id查看有哪些导师申请
     *
     * @param tid      老师id
     * @param isDelete 0已处理；1未处理
     * @return
     */
    @Select("SELECT s.sid applyId,s.name applyPerson,t.tid disposeId,t.name disposePerson,a.status type,a.a_time data FROM activity a,teacher t,student s WHERE t.tid=#{tid} AND a.is_delete=#{isDelete} AND t.tid=a.tid AND s.sid=a.sid AND a.status =21 OR a.status =24")
    @Results({
            @Result(column = "applyId", property = "applyId"),
            @Result(column = "applyPerson", property = "applyPerson"),
            @Result(column = "disposeId", property = "disposeId"),
            @Result(column = "disposePerson", property = "disposePerson"),
            @Result(column = "type", property = "type"),
            @Result(column = "data", property = "data"),
    })
    List<UnDoMsg> queryTeaApply(@Param("tid") Integer tid, @Param("isDelete") Integer isDelete);

    /**
     * 根据老师id查看有哪些小组申请
     *
     * @param tid      老师id
     * @param isDelete 0已处理；1未处理
     * @return
     */
    @Select("SELECT  s.sid applyId,s.name applyPerson,t.tid disposeId,t.name disposePerson,a.status type,a.a_time data FROM activity a,teacher t,student s WHERE t.tid=#{tid} AND a.is_delete=#{isDelete} AND t.group_id=a.group_id AND s.sid=a.sid AND a.status =1 OR a.status =4")
    @Results({
            @Result(column = "applyId", property = "applyId"),
            @Result(column = "applyPerson", property = "applyPerson"),
            @Result(column = "disposeId", property = "disposeId"),
            @Result(column = "disposePerson", property = "disposePerson"),
            @Result(column = "type", property = "type"),
            @Result(column = "data", property = "data"),
    })
    List<UnDoMsg> queryGroApply(@Param("tid") Integer tid, @Param("isDelete") Integer isDelete);
}
